/*
 * tcp_checksum.c
 *
 *  Created on: 2009-5-14
 *      Author: tian
 */

#include"mytcp.h"

unsigned short tcp_checksum(struct ip_fake_hdr *p_ip_fhdr,void *tcppkg){
	unsigned short sum=0;
	unsigned short *p=tcppkg;
	unsigned short *q=(void*)p_ip_fhdr;
	int size=sizeof(struct ip_fake_hdr);
	while(size>0){
		sum+=*(q++);
		size-=2;
	}
	size=p_ip_fhdr->tcp_l;
	while(size>1){
		sum+=*(p++);
		size-=2;
	}
	if(size==1){
		sum+=*((unsigned char*)p);
	}
	return (~sum);
}
